const Actions = require('./actions');
const DB = require('app/db');
import { Control } from 'react-keeper';
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {
    },

    onFetch: function (params, cb) {
        let t = this;
        DB.Teacher.get_warninfo_detail({
            schoolId: params.schoolId,
            teacherId: params.teacherId,
            studentId: params.studentId,
            warnId: params.warnId,
            warnTypeId: params.warnTypeId,
            warnGrade: '',
            warnLevel: '',
            warnDate: ''
        })
            .then((content) => {
                if (content.code == 1) {
                    content = content.data;
                    Object.assign(this.data, {
                        schoolId: params.schoolId,
                        teacherId: params.teacherId,
                        studentId: params.studentId,
                        warnId: params.warnId,
                        warnTypeId: params.warnTypeId
                    });
                    let { list, warnId, pushFlag } = content;
                    t.data.listdata = list;
                    t.updateComponent();
                }
            })
            .catch(function (error) {

            });
    },
    onNoticeParent: function (params, cb) {
        let t = this;
        let {
            schoolId,
            teacherId,
            studentId,
            warnId
        } = this.data;
        DB.Teacher.push_notice_parent({
            schoolId: schoolId,
            teacherId: teacherId,
            studentId: studentId,
            warnId: warnId
        })
            .then((content) => {
                if (content.code == 1) {
                    Control.go(-1)
                }
            })
            .catch(function (error) {

            });
    },
    updateComponent: function () {
        this.trigger(this.data);
    }
});
